home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Best of Shareware
/
Best of PC Windows Shareware 1.0 - Wayzata Technology (7111) (1993).iso
/
mac
/
ZIPPED
/
DOS
/
UTILITY
/
SRCH33.ZIP
/
SRCH.DOC
< prev
next >
Wrap
Text File
|
1992-10-17
|
11KB
|
305 lines
SRCH 3.3 - Fast pattern matcher (with not-so fast replacement)
--------------------------------------------------------------
Quick Introduction
------------------
Type SRCH with no arguments for a concise listing of options.
Introduction
------------
SRCH is a "grep-like" pattern matching program. (If you don't know
what grep is, don't worry about it!) In its simplest form, you
provide a pattern, and SRCH searches all the specified files for that
pattern, printing out any occurrences it finds. For example,
SRCH chocolate recipe.1 recipe.2 recipe.3
will search the three recipe files for the pattern "chocolate".
Every line that contains "chocolate" will be printed out.
You can specify as many files as you want, up to the MS-DOS limit
on the command line length. You can also use wildcard characters.
For example, to search all the recipe files, you could type:
SRCH chocolate recipe.*
SRCH's main advantage over other pattern matching programs is its
speed. It is based on the Boyer-Moore algorithm, and can search
faster than many other searching programs. The primary limitation
of SRCH is that it will not (yet) search for regular expressions
(i.e., you cannot have wildcards in the pattern).
SRCH is fast enough, especially on a hard disk, that it can replace
more elaborate tools (such as database and text retrieval programs)
when all that is needed is the ability look up information. Since
it works on plain text files, SRCH is quite flexible. You can use
your favorite word or text processor to enter information. You can
keep all your information in one big file, or (as with the recipe
example above) you may choose to keep each piece of information as
a separate file. This strategy works quite well for small to
medium size databases.
SRCH's Unix cousin, grep, is used extensively in this fashion.
This may be one of the reasons that it took so long for real
databases to appear in the Unix world! One important application
used by programmers is locating function and variable definitions
and references in a set of modules. For example, to find all
occurrences of function named "foobar" in a set of C files, you
could type:
SRCH foobar *.c *.h
With the -d option (see below), you can search an entire disk,
subdirectories and all. This can be quite useful when you've
misplaced some information. For example,
SRCH -d chocolate \
will find all occurrences of "chocolate" in any file on the current disk.
If Your Output Looks Strange
----------------------------
SRCH assumes that you are using ANSI.SYS (or something similar) in
your CONFIG.sys file. SRCH takes advantage of this to highlight
the matched patterns that are printed and to clear lines. If you
do not use an ANSI driver, then you will see some strange
characters adjacent to matched pattern. To eliminate this, use the
-h option:
SRCH -h chocolate recipe.*
If you are redirecting, capturing, or printing output, you will
also probably want to use this option.
Replacement
-----------
SRCH can also do pattern replacement. While it cannot replace patterns
anywhere near as fast as it can find them, it does a creditable job.
If you run the following command:
SRCH -r chocolate vanilla recipe.*
SRCH will go through all your recipe files and replace the pattern
"chocolate" with the pattern "vanilla". Normally, SRCH will print
out each line that contains "chocolate", and ask you if you want
to make the replacement in this line. You can answer:
y "yes, make this replacement"
n "no, do not make this replacement"
Ctrl-y "yes, and make any other replacements without asking"
Ctrl-n "no, and do not make any more replacements"
You must type one of these four characters; any other input will be
ignored. If the pattern occurs more than once in a line, you will
be asked about the replacement more than once.
If you know in advance that you do not want to be queried about each
line, use the -i option to turn off interactive mode. Even with the
-i option, all matching lines are shown; to eliminate this output,
just redirect the output to the NUL device:
SRCH -r chocolate vanilla recipe.* >nul
A word of caution: SRCH does not backup your file when it replaces
it. It is advisable to make a copy of your file before doing a
replace, in case you change your mind about the replacement. Note
that if you interrupt the replacement (with Ctrl-C) before it is
complete, NO changes will be made. However, if you let it run to
completion, your original file will be permanently changed.
Searching Based on Filenames
----------------------------
Using file masks and recursive directory search (see discussion of
the "-d" and "-m" options below), SRCH can be used to locate files
based on their name, rather than on their contents.
To find all recipe files on the C: drive:
SRCH -d -m recipe.* "" c:\
Every file is considered to match the empty pattern (""), so all
files generated with the file mask option will be located.
Other Options
-------------
SRCH's options are similar to those for the Unix "fgrep" command.
Usage: SRCH [options] <pattern> [replacement] [file-list]
If no files are specified, and SRCH is on the tail end of a pipe, then
SRCH will read from the pipe (standard input). The command:
DIR | SRCH recipe
will print out all filenames that contain the pattern "recipe".
If the pattern (or replacement) contains blanks, then it must be quoted:
SRCH "chocolate cake" recipe.*
The options are as follows:
-b Opens files in text mode, rather than the default binary
mode. This causes SRCH to treat the Ctrl-Z character as
the end of file; it also causes the -n option to count
each CR/LF pair as a single character (instead of two).
-c Only prints the number of lines that contained the pattern.
For example,
SRCH -c chocolate recipe.*
will tell you how many times the pattern chocolate occurs in
all the recipe files.
-d Recursively search any directories.
If one of the filenames is a directory, this option will make
SRCH move to that directory and search all the files in that
directory for the pattern. If any one of those files is a
directory, then SRCH moves down again, etc.
For example,
SRCH -d chocolate \
will search the entire disk for files containing "chocolate".
-e Take the next argument as the pattern. This is necessary
if you have a pattern that starts with '-', since anything
starting with that character is assumed to be an option.
For example,
SRCH -e -e srch.doc
will search this documentation for the pattern "-e".
-f Normally, SRCH pretends that there is no difference between
upper and lower case (this is called "case folding"). The
-f option turns case folding off, so that the case must
match exactly.
-h SRCH normally highlights the matched pattern in the line.
The -h option can be used to control how the highlighting
is done. Using -h alone turns off highlighting, which is
useful for running without an ANSI driver, or for printing
to files or a printer.
On the other hand, if you have the ANSI driver but do not
like the way things are highlighted, you can use the -h
option to specify the ANSI attributes for the highlight.
On a monochrome monitor, the following command will use
blinking reverse video as a highlight:
SRCH -h5;7 chocolate recipe.*
-i Turn off interactive mode. This controls two features:
(1) Display the name of each file as it is being searched.
Interactive mode displays the name of each file as it is being
searched. The display is overwritten, so only the last/current
name will appear. If SRCH's output is redirected, this information
will still appear on the screen. If you are not using an ANSI
driver, use the -h option to suppress the "clear to end of line"
control sequences (however, you will still notice some garbage
on the screen).
(2) Query user about each replacement. If replacement (-r)
is specified, interactive mode queries the user about each
replacement (see the discussion above on replacement). With
interactive mode turned off, all replacements are done without
user intervention.
-l Instead of listing all the occurrences of the pattern in each
file, just list the names of the files which contain the pattern.
This may speed up the search, since once the pattern is located
in a file, there is no need to search any further in that file.
-m <pat> Use specified file mask to filter out files. Normally, SRCH
searches the specified files; however, with the -d option,
SRCH also scans all file in subdirectories. A file mask is
used to limit the search to files with specific names. For
example:
SRCH -d -m "recipe.*" chocolate *.*
would search only files named "recipe.*" in the current
directory and in subdirectories. Multiple masks can be
specified:
SRCH -d -m "recipe.* menu.*" chocolate *.*
Remember to quote the mask (as in the above examples);
otherwise, if the current directory contains any files which
match the mask, an error will occur.
The file mask matching uses Unix-style (shell) matching,
rather than DOS style matching. For example, patterns like
"*abc.*" can be used. In addition, character classes are
supported. For example, "*.[ab]" matches "*.a" and "*.b".
(Note that the Unix-style matching is currently supported
only for file masks, not for the filename arguments
themselves.)
-n Print the address (byte number in file) of each match.
(Unfortunately, the Boyer-Moore algorithm used in SRCH makes
it difficult to obtain the line number.)
-r Perform a replacement. A second pattern is specified as the
replacement pattern; see the discussion above for more info.
-s Print nothing at all. This is to allow batch files to examine
the errorlevel without creating any output. SRCH returns the
following values:
0 a match was found
1 no matches were found
2 an error occurred (bad file, option error, etc.)
A Word from Our Sponsor
-----------------------
SRCH is distributed as shareware. If you find this program useful,
a $15 registration fee is requested.
SRCH is written in C; the current version is compiled with Microsoft
C version 6. SRCH also runs under Unix System V.
SRCH may be redistributed freely. It may not be sold for any
purpose without written permission from the author. If shipping,
handling, and/or tax is charged, the total sum may not exceed $5.
If you like SRCH, or have any suggestions, comments, questions
about current/future versions, or (heaven forbid!) bug reports,
please let me know. Thanks!
Jeff Dean
710 Chimalus
Palo Alto, CA 94306
USA
Revision History
----------------
3.3
Fixed replacement bug (introduced in 3.1 when binary
file support was added).
3.2
Added support for file masks (the -m option)
3.1
Added support for binary files (and the -b option)
3.0
Shareware release